<template>
  <table-layout>
    <filter-search slot="right" @search="_handleSearch" />
    <ex-table
      ref="table"
      :loading="loading"
      :table-column="tableColumn"
      :table-data="tableData"
      @pageSizeChange="handleSizeChange"
      @currentPageChange="handleCurrentChange"
    >
      <template v-slot:operate="{ scope }">
        <el-button @click="lookDetail(scope.row.id)">查看详情</el-button>
      </template>
    </ex-table>
    <detail-dialog
      v-if="detailDialog"
      :id="id"
      :visible.sync="detailDialog"
      @success="_handleSuccess"
    />
  </table-layout>
</template>
<script>
// components
import FilterSearch from './components/withdrawalAudit/FilterSearch'
import DetailDialog from './components/withdrawalAudit/DetailDialog'
// api
import {
  getList,
  getDetail,
  approved,
  reject
} from '@/api/withdrawalAudit'

// mixins
import handlePageMixin from '@/mixins/handlePageMixin'
import { param } from '@/utils'

export default {
  name: 'WithdrawalAudit',
  components: {
    FilterSearch,
    DetailDialog
  },
  mixins: [handlePageMixin],
  data() {
    return {
      loading: false,
      id: '',
      detailDialog: false,
      filter: {
        applyStartTime: '',
        applyEndTime: '',
        applyStatus: '',
        withdrawStatus: ''
      },
      tableColumn: [
        { prop: 'applyTime', label: '申请时间' },
        { prop: 'accountName', label: '账号名称' },
        { prop: 'type', label: '提现类型' },
        { prop: 'assetName', label: '提现资产名称' },
        { prop: 'worth', label: '资产价值/CNY' },
        { prop: 'applyNum', label: '申请数量' },
        { prop: 'money', label: '申请金额' },
        { prop: 'applyStatus', label: '申请结果' },
        { prop: 'withdrawStatus', label: '提现结果' },
        { prop: 'serialNum', label: '交易流水' },
        { label: '操作', slot: true, slotName: 'operate' }
      ],
      tableData: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    lookDetail(id) {
      this.id = id
      this.detailDialog = true
    },
    getList() {
      this.loading = true
      const params = {
        ...this.pageOptions,
        ...this.filter
      }
      console.log('params', params)
      getList(params).then(res => {
        const { total, records } = res.result
        console.log('提现列表', records)
        records.forEach(item => {
          // asset_type
          if (item.type == 1) {
            item.type = '资产提现'
          } else if (item.type == 2) {
            item.type = '通兑提现'
          }
          if (item.applyStatus == 1) {
            item.applyStatus = '待审核'
          } else if (item.applyStatus == 2) {
            item.applyStatus = '审核拒绝'
          } else if (item.applyStatus == 3) {
            item.applyStatus = '审核通过'
          }
          if (item.withdrawStatus == 1) {
            item.withdrawStatus = '提现成功 '
          } else if (item.withdrawStatus == 2) {
            item.withdrawStatus = '提现失败'
          }
        })

        this.$refs.table.pageOptions.total = total
        this.tableData = records
      }).finally(() => {
        this.loading = false
      })
    },
    _handleSuccess() {
      this.getList()
    }
  }
}
</script>
<style lang="scss" scoped>

</style>
